#include <iostream>
#include <vector>
#include <utility>

struct RouteEntry {
    int network;
    int hopCount;
    int nextHop;
};

std::vector<RouteEntry> updateRoutingTable(const std::vector<RouteEntry>& r1Table, const std::vector<RouteEntry>& r2Table) {
    std::vector<RouteEntry> newR1Table = r1Table;
    for (const auto& r2Entry : r2Table) {
        bool found = false;
        for (auto& r1Entry : newR1Table) {
            if (r1Entry.network == r2Entry.network) {
                found = true;
                if (r2Entry.hopCount + 1 < r1Entry.hopCount) {
                    r1Entry.hopCount = r2Entry.hopCount + 1;
                    r1Entry.nextHop = r2Entry.nextHop;
                }
                break;
            }
        }
        if (!found) {
            RouteEntry newEntry;
            newEntry.network = r2Entry.network;
            newEntry.hopCount = r2Entry.hopCount + 1;
            newEntry.nextHop = r2Entry.nextHop;
            newR1Table.push_back(newEntry);
        }
    }
    return newR1Table;
}

void printRoutingTable(const std::vector<RouteEntry>& table) {
    std::cout << "Network\tHop Count\tNext Hop" << std::endl;
    for (const auto& entry : table) {
        std::cout << entry.network << "\t" << entry.hopCount << "\t\t" << entry.nextHop << std::endl;
    }
}

int main() {
    std::vector<RouteEntry> r1Table = {
        {1, 2, 2},
        {2, 3, 3}
    };

    std::vector<RouteEntry> r2Table = {
        {1, 1, 2},
        {3, 2, 3}
    };

    std::vector<RouteEntry> newR1Table = updateRoutingTable(r1Table, r2Table);

    printRoutingTable(newR1Table);

    return 0;
}    